package com.ruoyi.order.service.impl;

import java.util.*;
import java.util.function.Function;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.order.domain.Vo.ProductVo;
import com.ruoyi.order.domain.app.Vo.*;
import org.springframework.stereotype.Service;
import com.ruoyi.order.mapper.ProductMapper;
import com.ruoyi.order.domain.Product;
import com.ruoyi.order.service.IProductService;
import com.ruoyi.common.core.text.Convert;

import javax.annotation.Resource;

/**
 * 产品表Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-02-04
 */
@Service
public class ProductServiceImpl implements IProductService 
{
    @Resource
    private ProductMapper productMapper;



    /**
     * 查询产品表
     * 
     * @param productID 产品表主键
     * @return 产品表
     */
    @Override
    public Product selectProductByProductID(Integer productID)
    {
        return productMapper.selectProductByProductID(productID);
    }


    /**
     * 查询产品表列表
     * 
     * @param product 产品表
     * @return 产品表
     */
    @Override
    public List<Product> selectProductList(Product product)
    {
        return productMapper.selectProductList(product);
    }

    /**
     * 新增产品表
     * 
     * @param product 产品表
     * @return 结果
     */
    @Override
    public int insertProduct(Product product)
    {
        product.setCreateTime(DateUtils.getNowDate());
        return productMapper.insertProduct(product);
    }

    /**
     * 修改产品表
     * 
     * @param product 产品表
     * @return 结果
     */
    @Override
    public int updateProduct(Product product)
    {
        product.setUpdateTime(DateUtils.getNowDate());
        return productMapper.updateProduct(product);
    }

    /**
     * 批量删除产品表
     * 
     * @param productIDs 需要删除的产品表主键
     * @return 结果
     */
    @Override
    public int deleteProductByProductIDs(String productIDs)
    {
        return productMapper.deleteProductByProductIDs(Convert.toStrArray(productIDs));
    }

    /**
     * 删除产品表信息
     * 
     * @param productID 产品表主键
     * @return 结果
     */
    @Override
    public int deleteProductByProductID(Integer productID)
    {
        return productMapper.deleteProductByProductID(productID);
    }

    @Override
    public List<ProductVo> getProductPages(String productName) {
        Map<String,Object> map = new HashMap<>();

        map.put("productName" , productName);
        map.put("state" , 0 );
        List<ProductVo> list = productMapper.getProductPages(map);
        return list;
    }

    @Override
    public List<ProductVo> getProductPagesList() {
        Map<String,Object> map = new HashMap<>();
        map.put("state" , 0 );
        List<ProductVo> list = productMapper.getProductPagesList(map);
        return list;
    }

    @Override
    public List<Banner> getProductImgs() {
        Map<String,Object> map = new HashMap<>();
        map.put("state" , 0 );
        List<Banner> list = productMapper.getProductImgs(map);
        return list;
    }

    @Override
    public List<ProductViewDetail>getsearchProdPage(Integer categoryId) {
        Map<String,Object> map = new HashMap<>();
        map.put("state" , 0 );
        map.put("categoryID" ,categoryId);
        List<ProductViewDetail> list =  productMapper.getsearchProdPage(map);
        return list;
    }

    @Override
    public List<SkuVo> getSku(Integer prodId) {
        Map<String,Object> map = new HashMap<>();
        map.put("state" , 0 );
        map.put("productID" ,prodId);
        List<SkuVo>list =  productMapper.getSku(map);
        System.out.println(Arrays.toString(list.toArray()));
        return list;
    }

    @Override
    public ProdInfoResultVo getProdInfo(Integer prodId) {
        Map<String,Object> map = new HashMap<>();
        map.put("state" , 0 );
        map.put("productID",prodId);
        ProdInfoResultVo list =  productMapper.getProdInfo(map);
        return list;
    }

    @Override
    public ProductViewResultVo getSearchProdPageByprodName(String prodName,Integer current,Integer size) {
        ProductViewResultVo result = new ProductViewResultVo();
        Map<String,Object> map = new HashMap<>();
        map.put("state" , 0 );
        map.put("productName",prodName);
        List<ProductViewDetail> list =  productMapper.getSearchProdPageByprodName(map);
        if(list.size()>0&&list!=null){
            result.setRecords(list);
            result.setTotal(list.size());
            result.setOptimizeCountSql(true);
            result.setSearchCount(true);
            result.setPages(1);
            result.setCurrent(current);
            result.setSize(size);
        }
        return result;
    }

    @Override
    public boolean saveBatch(Collection<Product> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdateBatch(Collection<Product> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean updateBatchById(Collection<Product> entityList, int batchSize) {
        return false;
    }

    @Override
    public boolean saveOrUpdate(Product entity) {
        return false;
    }

    @Override
    public Product getOne(Wrapper<Product> queryWrapper, boolean throwEx) {
        return null;
    }

    @Override
    public Map<String, Object> getMap(Wrapper<Product> queryWrapper) {
        return null;
    }

    @Override
    public <V> V getObj(Wrapper<Product> queryWrapper, Function<? super Object, V> mapper) {
        return null;
    }

    @Override
    public BaseMapper<Product> getBaseMapper() {
        return null;
    }

    @Override
    public Class<Product> getEntityClass() {
        return null;
    }
}
